package com.jiaai.cloud.wx.controller;

import com.jiaai.cloud.base.entity.RestResultGenerator;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.wx.entity.TWxalterimg;
import com.jiaai.cloud.wx.service.ITWxalterimgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-09-08
 */
@Controller
@RequestMapping("/api/v1/twxalterimg")
public class TWxalterimgController {

    @Autowired
    private ITWxalterimgService itWxalterimgService;

    /**
     * 首页随机获取获取轮播的图片, 最多5张
     * @return
     * @throws ServiceException
     */
    @RequestMapping(value = "/getalterimg", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"} )
    @ResponseBody
    public Object getAlterImg() throws ServiceException {
        List<TWxalterimg> list = itWxalterimgService.getAlterImg();
        try {
            return RestResultGenerator.genSuccessResult(list);
        } catch (Exception e){
            throw new ServiceException("获取失败", e.getMessage());
        }
    }
}
